package cn.com.zhangwoo.microstar.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import cn.com.microstar.activity.R;
import cn.com.zhangwoo.microstar.http.ImageLoader;
import cn.com.zhangwoo.microstar.http.VolleySingleton;
import cn.com.zhangwoo.microstar.http.ImageLoader.Type;
import cn.com.zhangwoo.microstar.inteface.IUtilDB;
import cn.com.zhangwoo.microstar.utildb.CommonToast;
/***
 * GridView公共适配器
 * @author Administrator
 *
 */
public class GridViewAdapter extends BaseAdapter {
	
	private LayoutInflater inflater;
	private ImageLoader imageLoder0;//图片加载工具
	private List<String>  listData;
	private String[]  listDataa;
	private Context context;
	private com.android.volley.toolbox.ImageLoader mImageLoader;
	public GridViewAdapter(Context context,String[]  listData) {
		this.inflater=LayoutInflater.from(context);
		this.listDataa=listData;
		this.context=context;
		imageLoder0 = ImageLoader
				.getInstance(3, Type.LIFO);
		mImageLoader=VolleySingleton.getVolleySingleton(context).getImageLoader();
	}

	@Override
	public int getCount() {
		return listDataa.length;
	}

	@Override
	public Object getItem(int position) {
		//TODO Auto-generated method stub
		return listDataa[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView mImageView;
		if (null==convertView) {
			convertView=inflater.inflate(R.layout.item_supermarket_gridview, null);
			mImageView=(ImageView) convertView.findViewById(R.id.item_supermarket_gridviewImage);
			convertView.setTag(mImageView);
		}
		else
		{
			mImageView=(ImageView) convertView.getTag();
		}
		try {
			//imageLoder0.loadImage(IUtilDB.uu[0], mImageView, true);
			mImageLoader.get(listDataa[position], 
					com.android.volley.toolbox.ImageLoader.getImageListener(mImageView,R.drawable.zhangwo_hometop2, R.drawable.zhangwo_hometop2));
		} catch (Exception e) {
			mImageView.setImageResource(IUtilDB._TOPHOMEPAGEIMG[0]);
		}
		return convertView;
	}
	}
